/*
 * Copyright (c) 2011, Brookhaven National Laboratory
 * All rights reserved.
 * The software in this package is published under the terms
 * of the BSD license a copy of which has been included with
 * this distribution in the license.txt file.
 */

#include "oxtypes/impl/DynamicTypeImpl.h"

#include "dds/type/dynamic/detail/DynamicTypeMember.h"

using dds::type::MemberId;
using dds::type::dynamic::DynamicTypeMember;
using dds::type::dynamic::DynamicTypeMembersByName;
using dds::type::dynamic::DynamicTypeMembersById;
using dds::type::dynamic::AnnotationDescriptor;
using dds::type::dynamic::AnnotationDescriptorSeq;

namespace oxtypes { namespace impl {

DynamicTypeImpl::DynamicTypeImpl() {
}

DynamicTypeImpl::DynamicTypeImpl(
   const dds::type::dynamic::TypeDescriptor& td, 
   const std::list<DynamicTypeMember>& members, 
   const std::list<AnnotationDescriptor>& annotations){

  oxtypes::delegate::DynamicType* dt = new oxtypes::delegate::DynamicType();

  // type descriptor

  dt->td = td;

  // members

  if(members.size() != 0) {
    dt->members.reset(new DynamicTypeMembersByName);
    dt->memberByIds.reset(new DynamicTypeMembersById);
  }

  std::list<DynamicTypeMember>::const_iterator im;

  for(im = members.begin(); im != members.end(); im++){
    dt->members->insert(
       std::pair<std::string, DynamicTypeMember> (im->name(), *im));
    dt->memberByIds->insert(
       std::pair<MemberId, DynamicTypeMember> (im->id(), *im));
  }

  // annotations

  /*

  if(annotations.size() != 0) {
    td->annotations.reset(new AnnotationDescriptorSeq());
  } 

  std::list<AnnotationDescriptor>::const_iterator ia;

  for(ia = aannotations.begin(); ia != annotations.end(); ia++){
    td->anotations->push_back(*ia); 
  } 

  */

  // delegate

  d_ = dds::type::dynamic::detail::DynamicType(dt);  

}

}}
